package cn.tedu._05mvcboot03.common.response;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    @ApiModelProperty(value = "枚举状态码")
    private Integer state;
    @ApiModelProperty(value = "提示消息")
    private String message;
    @ApiModelProperty(value = "具体数据")
    private Object data;

    public JsonResult(StatusCode statusCode, Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    /**
     * 操作成功2个静态方法
     */
    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

    public static JsonResult ok() {
        return ok(null);
    }

    /**
     * 参数校验失败2个静态方法
     */
    public static JsonResult fail(Object data){
        return new JsonResult(StatusCode.VALIDATED_ERROR, data);
    }

    public static JsonResult fail(){
        return fail(null);
    }
}









